package com.example.demo.common;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName：MyTransform
 * @Author: admin
 * @Date: 2024/11/28 16:11
 * @Description: 对象转化帮助类
 */
@Slf4j
public class MyTransform {

    /* *
     * @Title: objectToInt
     * @Author: admin
     * @Date: 2024-11-28 16:13:54
     * @Params: [value, def]
     * @Return: int
     * @Description: 转为int
     */
    public static int objectToInt(Object value, int def) {
        int result = def;
        try {
            if (value == null) {
                return def;
            }
            String str = String.valueOf(value);
            if (MyFunction.stringIsNullOrWhiteSpace(str)) {
                return def;
            }
            result = Integer.parseInt(str.trim());
            return result;
        } catch (Exception ex) {
            log.error("字符串转int类型异常，objectToInt(value={})", value, ex);
            return def;
        }
    }
}
